﻿
using BankerenClient.Events;
using Caliburn.Micro;

namespace BankerenClient
{
    public class JoinGameViewModel : Screen, IMainScreen
    {
        #region Fields

        private BindableCollection<ServerInfoViewModel> servers;
        private string serverHost;

        #endregion

        #region Properties

        public BindableCollection<ServerInfoViewModel> Servers
        {
            get { return this.servers; }
        }

        public string ServerHost
        {
            get { return this.serverHost; }
            set
            {
                this.serverHost = value;
                NotifyOfPropertyChange(() => ServerHost);
                NotifyOfPropertyChange(() => CanAddServer);
            }
        }

        public bool CanAddServer
        {
            // TODO: Change this to only accept valid server ip/hostname?
            get { return !string.IsNullOrWhiteSpace(this.serverHost); }
        }

        public bool CanJoinGame
        {
            get { return true; }
        }

        #endregion

        #region Ctor

        public JoinGameViewModel()
        {
            this.DisplayName = "Join Game";
            this.servers = new BindableCollection<ServerInfoViewModel>();
            for (int i = 0; i < 5; i++)
            {
                this.servers.Add(new ServerInfoViewModel());
            }
            this.serverHost = null;
        }

        #endregion

        #region Methods

        public void JoinGame()
        {
            EventAggregationProvider.EventAggregator.Publish<BankerenEvent>(new BankerenEvent(BankerenEventType.GotoPlayGame));
        }

        public void AddServer()
        {

        }

        public void Refresh()
        {

        }

        public void Back()
        {
            EventAggregationProvider.EventAggregator.Publish<BankerenEvent>(new BankerenEvent(BankerenEventType.GotoMainMenu));
        }

        #endregion
    }
}
